package com.GUI.Lesson05;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class JButtonDemo02 extends JFrame {

    public JButtonDemo02(){
        //获得容器
        Container container = this.getContentPane();

        //将一个图片变成图标
        URL resource = JButtonDemo.class.getResource("tx.png");
        Icon icon = new ImageIcon(resource);

        //单选框
        JRadioButton button1 = new JRadioButton("单选框1");
        JRadioButton button2 = new JRadioButton("单选框2");
        JRadioButton button3 = new JRadioButton("单选框3");
        //由于单选框只能选一个，所以需要分组，组内只能选一个
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(button1);
        buttonGroup.add(button2);
        buttonGroup.add(button3);

        container.add(button1,BorderLayout.NORTH);
        container.add(button2,BorderLayout.CENTER);
        container.add(button3,BorderLayout.SOUTH);
        //基本属性
        this.setVisible(true);
        this.setBounds(20,20,100,100);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) {
        new JButtonDemo02();
    }
}
